"""
A class to exercise the JT core functions.
"""
import itk
import vtk
import JT
import Calibration
from numpy import array

def Test_JTVolumeRendering():
    """
    Test the volume rendering implemented in JT
    """
    inputVolFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.mha'
    staFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.sta'
    calFile = 'C:/Users/bryan/bryan-code/trunk/TestData/ext_cal1.txt'

#===============================================================================
#    
#    Generate Lateral Projection
#    
#===============================================================================
    xraycam = JT.XRayCamera()
    drr = JT.DRR()

    drr.SetXRayCamera(xraycam)
    drr.SetVolumeFilename(inputVolFileName)

#===============================================================================
#    
#    Automatic calibration
#    
#===============================================================================
    cal = Calibration.ExternalCalibration()
    cal.LoadConsolidatedCalibration(calFile)
    cal.LoadStaFile(staFile)
    
    xraycam.SetExternalCalibration(cal)
    
    drr._volume.SetOriginalTransform(cal._VolumeT)
    drr._volume.SetBodyCenter((3.906, 2.17, -7.378))
    
    #Set the volume mapper to RayCast (more accurate, but slower)
    #Comment out to use TextureMapper
    #drr._volume.UseRayCastMapper()
    #drr.InteractionOff()
    
    drr.SetBlackOnWhiteImage()

    drr.Render()
    print "Time to Render: ", drr.GetRenderTime(), ", Frame Rate: ", 1/drr.GetRenderTime()

    #Debugging, save the final generated image
    drr.SaveGeneratedImage('C:/Users/bryan/bryan-code/trunk/Images/CurrentDRR.mhd')


if __name__ == "__main__":
    Test_JTVolumeRendering()